package com.example.universitylibraryback.pipeline.filter;

import com.example.universitylibraryback.pipeline.BorrowContext;
import com.example.universitylibraryback.pipeline.Filter;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;

@Component
public class BorrowRecordCreationFilter implements Filter<BorrowContext> {
    @Override
    public void process(BlockingQueue<BorrowContext> inputQueue, BlockingQueue<BorrowContext> outputQueue) throws InterruptedException {
        while (true) {
            BorrowContext context = inputQueue.take();
            if (context.isValid()) {
                //生成借阅记录ID
                context.setBorrowRecordId(UUID.randomUUID().toString());
                //设置借阅日期为当前时间
                context.setBorrowDate(new Date());
                //设置到期日期（例如：30天后）
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(Calendar.DAY_OF_MONTH, 30);
                context.setDueDate(calendar.getTime());
            }
            outputQueue.put(context);
        }
    }
}